<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="待审核" name="first">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="专利名称" prop="proName">
            <el-input v-model="queryParams.proName" placeholder="请输入专利名称" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="上传人" prop="proAuthor">
            <el-input v-model="queryParams.proAuthor" placeholder="请输入专利上传人" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="examineList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" align="center" />
          <el-table-column label="专利编号" align="center" prop="id" width="90" />
          <el-table-column label="专利名称" align="center" prop="proName" />
          <el-table-column label="专利文件" align="center" prop="proFile" width="200">
            <template slot-scope="scope">
              <a @click="downloadFile(scope.row)" class="fileStyle">{{downName(scope.row.proFile)}}</a>
              <el-progress :percentage="progress1" :format="format" v-if="scope.row.id==rowid?true:false">
              </el-progress>
            </template>
          </el-table-column>
          <!-- <el-table-column label="专利类型" align="center" prop="proType" /> -->
          <el-table-column label="专利描述" align="center" prop="proDescr" />
          <el-table-column label="上传人" align="center" prop="proAuthor" />
          <el-table-column label="上传时间" align="center" prop="proCreatetime" width="200PX" />
          <el-table-column label="项分组状态" align="center" prop="proGroupStatus">
            <div slot-scope="scope">
              {{scope.row.proGroupStatus==0?proGroupStatus="未分组":proGroupStatus="已分组"}}
            </div>
          </el-table-column>
          <el-table-column label="审核状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status==0">待审核</el-tag>
              <el-tag type="success" v-else-if="scope.row.status==1">已通过</el-tag>
              <el-tag type="danger" v-else="scope.row.status==2">被驳回</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px">
            <template slot-scope="scope">
              <el-button style="color:green" size="mini" type="text" icon="el-icon-success"
                @click="handleUpdate(scope.row)" v-hasPermi="['project:projectData:edit']">通过审批</el-button>
              <el-button style="color:red" size="mini" type="text" icon="el-icon-error" @click="handleReject(scope.row)"
                v-hasPermi="['project:projectData:edit']">驳回专利</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['project:projectData:remove']">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </el-tab-pane>
      <!-- 通过审核数据面板 -->
      <el-tab-pane label="通过审核" name="second">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="专利名称" prop="proName">
            <el-input v-model="queryParams.proName" placeholder="请输入专利名称" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="上传人" prop="proAuthor">
            <el-input v-model="queryParams.proAuthor" placeholder="请输入专利上传人" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="adoptList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" align="center" />
          <el-table-column label="专利编号" align="center" prop="id" width="90" />
          <el-table-column label="专利名称" align="center" prop="proName" />
          <el-table-column label="专利文件" align="center" prop="proFile" width="200">
            <template slot-scope="scope">
              <a @click="downloadFile(scope.row)" class="fileStyle">{{downName(scope.row.proFile)}}</a>
              <el-progress :percentage="progress1" :format="format" v-if="scope.row.id==rowid?true:false">
              </el-progress>
            </template>
          </el-table-column>
          <!-- <el-table-column label="专利类型" align="center" prop="proType" /> -->
          <el-table-column label="专利描述" align="center" prop="proDescr" />
          <el-table-column label="上传人" align="center" prop="proAuthor" />
          <el-table-column label="上传时间" align="center" prop="proCreatetime" width="200PX" />
          <el-table-column label="项分组状态" align="center" prop="proGroupStatus">
            <div slot-scope="scope">
              {{scope.row.proGroupStatus==0?proGroupStatus="未分组":proGroupStatus="已分组"}}
            </div>
          </el-table-column>
          <el-table-column label="审核状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status==0">待审核</el-tag>
              <el-tag type="success" v-else-if="scope.row.status==1">已通过</el-tag>
              <el-tag type="danger" v-else="scope.row.status==2">被驳回</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['project:projectData:remove']">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </el-tab-pane>
      <el-tab-pane label="被驳回" name="third">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="专利名称" prop="proName">
            <el-input v-model="queryParams.proName" placeholder="请输入专利名称" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="上传人" prop="proAuthor">
            <el-input v-model="queryParams.proAuthor" placeholder="请输入专利上传人" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="reject" @selection-change="handleSelectionChange">
          <el-table-column type="selection" align="center" />
          <el-table-column label="专利编号" align="center" prop="id" width="90" />
          <el-table-column label="专利名称" align="center" prop="proName" />
          <el-table-column label="专利文件" align="center" prop="proFile" width="200">
            <template slot-scope="scope">
              <a @click="downloadFile(scope.row)" class="fileStyle">{{downName(scope.row.proFile)}}</a>
              <el-progress :percentage="progress1" :format="format" v-if="scope.row.id==rowid?true:false">
              </el-progress>
            </template>
          </el-table-column>
          <!-- <el-table-column label="专利类型" align="center" prop="proType" /> -->
          <el-table-column label="专利描述" align="center" prop="proDescr" />
          <el-table-column label="上传人" align="center" prop="proAuthor" />
          <el-table-column label="上传时间" align="center" prop="proCreatetime" width="200PX" />
          <el-table-column label="项分组状态" align="center" prop="proGroupStatus">
            <div slot-scope="scope">
              {{scope.row.proGroupStatus==0?proGroupStatus="未分组":proGroupStatus="已分组"}}
            </div>
          </el-table-column>
          <el-table-column label="审核状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status==0">待审核</el-tag>
              <el-tag type="success" v-else-if="scope.row.status==1">已通过</el-tag>
              <el-tag type="danger" v-else="scope.row.status==2">被驳回</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['project:projectData:remove']">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import { listProjectData, getProjectData, delProjectData, addProjectData, updateProjectData } from "@/api/system/project/projectData";
import download from "@/plugins/download"

export default {
  name: "ProjectData",
  data () {
    return {
      activeName: 'first',
      // 遮罩层
      loading: true,
      statusText: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利数据表格数据
      projectDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      rowid: '',
      progress1: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: null,
        proFile: null,
        proType: null,
        proDescr: null,
        proAuthor: null,
        proCreatetime: null,
        proGroupStatus: null,
        groupId: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      examineList: [],
      adoptList: [],
      reject: []
    };
  },
  created () {
    this.getList();
  },
  computed: {
    progress () {
      return this.$store.state.myProject.progress
    }
  },
  watch: {
    progress (newval, oldval) {
      this.progress1 = newval
    }
  },
  methods: {
    format (percentage) {
      return percentage === 100 ? '完成' : `${percentage}%`;
    },
    downloadFile (data) {
      if (this.progress1 != 0) {
        this.$message({
          message: '已经有一个专利正在下载',
          type: 'warning'
        });
      } else {
        this.rowid = data.id
        download.resource(data.proFile)
        setTimeout(() => {
          this.rowid = ""
          this.progress1 = 0;
        }, 3000)

      }

    },
    downName (file) {
      let data = file.split("/");
      return data[data.length - 1];
    },
    /** 查询专利数据列表 */
    getList () {
      this.loading = true;
      this.examineList = []
      this.adoptList = []
      this.reject = []
      listProjectData(this.queryParams).then(response => {
        this.projectDataList = response.rows;
        this.total = response.total;
        this.loading = false;
        for (var i = 0; i < this.projectDataList.length; i++) {
          if (this.projectDataList[i].status == 0) {
            this.examineList.push(this.projectDataList[i])
          } else if (this.projectDataList[i].status == 1) {
            this.adoptList.push(this.projectDataList[i])
          } else {
            this.reject.push(this.projectDataList[i])
          }
        }
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        proName: null,
        proFile: null,
        proType: null,
        proDescr: null,
        proAuthor: null,
        proCreatetime: null,
        proGroupStatus: 0,
        groupId: null,
        userId: null,
        status: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加专利数据";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      getProjectData(id).then(response => {
        this.form = response.data;
        this.form.status = 1
        updateProjectData(this.form).then(response => {
          this.$modal.msgSuccess("审核通过");
          this.getList();
        });
      });
    },
    handleReject (row) {
      this.reset();
      const id = row.id || this.ids
      getProjectData(id).then(response => {
        this.form = response.data;
        this.form.status = 2
        updateProjectData(this.form).then(response => {
          this.$modal.msgSuccess("已驳回专利");
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除专利数据编号为"' + ids + '"的数据项？').then(function () {
        return delProjectData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('project/projectData/export', {
        ...this.queryParams
      }, `projectData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.statusActive1 {
  color: #e6a23c;
  background: #fdf6ec;
  border-color: #f5dab1;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid #dcdfe6;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  padding: 7px 8px;
  font-size: 14px;
  border-radius: 4px;
}

.statusActive2 {
  color: #909399;
  background: #f4f4f5;
  border-color: #d3d4d6;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid #dcdfe6;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  padding: 7px 8px;
  font-size: 14px;
  border-radius: 4px;
}
.fileStyle {
  padding: 12px;
  color: #442ed0;
}
.fileStyle:hover {
  text-decoration: underline !important;
  cursor: pointer;
  color: #2300ff;
}
</style>